<template>
  <div class="tree-banner">
    <el-header style="font-size: 20px; font-weight: bold">
      <i class="el-icon-document" style="margin-right: 15px" />
      <span>资产栏目</span>
      <el-dropdown style="float: right">
        <el-button style="background-color: rgba(20, 20, 20, 0.219); border: 1px solid #777" type="primary">
          更多支点  <i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>支点一</el-dropdown-item>
          <el-dropdown-item>支点二</el-dropdown-item>
          <el-dropdown-item>支点三</el-dropdown-item>
          <el-dropdown-item>支点四</el-dropdown-item>
          <el-dropdown-item>支点五</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </el-header>
    <div class="tree-contain">
      <el-table fit :data="tableData" border style="width: 100%">
        <el-table-column type="selection" prop="id" align="center" width="45" />
        <el-table-column prop="money_ip" label="IP地址" />
        <el-table-column label="状态与端口信息">
          <template slot-scope="scope">
            <div>
              <div>{{ scope.row.money_port.status }}</div>
              <div>{{ scope.row.money_port.MAC }}</div>
              <div>{{ scope.row.money_port.VENDOR }}</div>
              <div>{{ scope.row.money_port.DEVICE }}</div>
              端口开放情况：
              <pre>{{ scope.row.money_port.PORTS }}</pre>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="money_status" label="资产其他信息" width="500">
          <template slot-scope="scope">
            <div>
              <div>{{ scope.row.money_status.RTSP }}</div>
              ONVIF组件：
              <pre>{{ scope.row.money_status.ONVIF }}</pre>
              摄像头网络组件：
              <pre>{{ scope.row.money_status.ONET }}</pre>
              摄像头安全组件：
              <pre>{{ scope.row.money_status.OSEC }}</pre>
              摄像头系统组件：
              <pre>{{ scope.row.money_status.OSYS }}</pre>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="200">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="openSettingPanel(scope.row, scope.$index)"
              >编辑</el-button
            >
            <el-button
              size="mini"
              type="danger"
              @click="removeTodo(scope.$index)"
              >删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-form ref="loginFormRef">
        <el-button
          style="
            float: right;
            padding: 15px 47px 15px 47px;
            margin: 20px 30px 20px 0px;
          "
          type="primary"
          @click="reset()"
          >重置</el-button
        >
      </el-form>
    </div>
    <div style="clear: both" />
    <add-or-update
      v-if="addOrUpdateVisible"
      ref="addOrUpdate"
      @refreshDataList="getData"
    ></add-or-update>

    <el-dialog title="设置" :visible.sync="dialogFormVisible">
      <el-form :model="detailForm">
        <el-form-item label="IP地址" :label-width="formLabelWidth">
          <el-input v-model="detailForm.info" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="状态与端口信息" :label-width="formLabelWidth">
          <el-input
            v-model="detailForm.ipLocation"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="资产其他信息" :label-width="formLabelWidth">
          <el-input v-model="detailForm.total" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="setting">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  data() {
    return {
      tableData: [],
      dialogFormVisible: false,
      detailForm: {
        id: '',
        info: '',
        ipLocation: '',
        total: '',
      },
      formLabelWidth: '120px',
      addOrUpdateVisible: false,
    }
  },
  mounted() {
    const url = 'http://localhost:5000/ipc_port_list'
    axios.get(url).then((response) => {
      const result = response.data
      this.tableData = result.tableData
    })
  },
  methods: {
    openSettingPanel(row, index) {
      for (var key in row) {
        this.detailForm[key] = row[key]
      }
      this.detailForm.index = index
      this.dialogFormVisible = true
    },
    setting() {
      this.$set(this.tableData, this.detailForm.index, this.detailForm)
      this.dialogFormVisible = false
    },
    

    handleClick() {
      alert('button click')
    },

    removeTodo: function (index) {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.tableData.splice(index, 1)
          this.$message({
            type: 'success',
            message: '删除成功!',
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除',
          })
        })
    },

    handleClose(done) {
      this.$confirm('确认关闭？')
        .then((_) => {
          done()
        })
        .catch((_) => {})
    },
    reset() {
      // 页面刷新
      const url = 'http://localhost:5000/money_del'
      axios.get(url).then((response) => {
        const result = response.data
      })
      location.reload()
    },
    handleEdit(index, row) {
      console.log(index, row)
    },
    handleDelete(index, row) {
      console.log(index, row)
    },
  },
}
</script>

<style lang="scss" scoped>
.tree-banner {
  margin: 0.3%;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.tree-contain {
  width: 100%;
  box-shadow: rgba(0, 0, 0, 0.671);
}

.el-header {
  background-color: rgba(51, 48, 51, 0.219);
  color: #333;
  line-height: 60px;
}

.el-dropdown {
  vertical-align: top;
}
.el-dropdown + .el-dropdown {
  margin-left: 15px;
}
.el-icon-arrow-down {
  font-size: 12px;
}

.el-button {
  margin: 5px;
}

.el-table th > .cell {
  display: inline-block;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  position: relative;
  vertical-align: middle;
  padding-left: 15px;
  padding-right: 10px;
  width: 100%;
}
</style>
